<?php

namespace maotool\core\text\password\rule;

use maotool\core\text\password\PasswdStrengthItem;
use maotool\core\text\password\PasswdStrengthRule;
use maotool\core\text\password\result\PasswdStrengthError;
use maotool\core\text\password\result\PasswdStrengthIgnore;
use maotool\core\text\password\result\PasswdStrengthSuccess;

class MaxLengthRule implements PasswdStrengthRule
{

    protected $max;

    protected $message;

    public function __construct($max = 32, $message = "密码长度太长")
    {
        $this->max = $max;
        $this->message = $message;
    }

    function handle($password)
    {
        if (strlen($password) > $this->max) {
            $passwdStrengthError = new PasswdStrengthError();
            $passwdStrengthError->setMessage($this->message);
            $passwdStrengthError->setName("maxLength");
            return $passwdStrengthError;
        }
        $passwdStrengthIgnore = new PasswdStrengthIgnore();
        $passwdStrengthIgnore->setName("maxLength");
        return $passwdStrengthIgnore;
    }

}